/* 
File: script.js
Author: Brannen Sorem
Description:
	Controller for header.php (template) - 'Controller' in MVC
	Provides interaction between user and site.
		Hovering tips
		Weather loading - with zip code
		Adjustable content size based on window size - very clever
		Clickable links

*/

$(document).ready(function(){
		
	// add tip styling
	$(".tip").tipTip({maxWidth: "auto"});
	
	// make main link DIV's active links
	$(".clickable").bind("click", function(){
		window.location = $(this).find("a").attr("href");
	});
	
	////////////////////// WEATHER FUNCTIONS /////////////////////////
	// add weather to page in place of placeholder
	$("#weather").children().remove();
	
	$("#weather").append(weather_element);
	
	// add zip code input box to weather
	$("<div></div>").attr("id", "zip_box")
		.append(zip_element)
		.appendTo("#zip_input");
	
	$("#zip_box_input").focus(function(){
		$(this).val('');
	});
	
	// if zip code button clicked, add frame with weather data
	$("#zip_button").click(function(){
		var weather_link = "http://www.accuweather.com/us/ca/palo_alto/" + $("#zip_box_input").val() + "/forecast-details.asp";
				
		$("#content").html('');
		$("<iframe></iframe>").attr("id", "weather_frame")
			.css({"width": (case_width - side_width - 100), "height": (screen.height - 40)})
			.attr("src", weather_link).appendTo("#content");
	});
	///////////////////////////////////////////////////////////////////
	
	////////////////////// WIDTH OF CONTENT /////////////////////////
	// get width of screen to adjust content width
	var side_width = parseInt($("#left-column").css("width"));
	var case_width = parseInt($("#case").css("width"));
	if (isNaN(case_width)){
		case_width = 1000;
	}
	//alert((case_width) + " " + (side_width) + " " + (screen.height));
	
	// adjust content width
	$("#content").css({"width": (case_width - side_width - 60), "height": (screen.height)});
	
	// if window is resized, resize content div accordingly
	$(window).resize(function(){
		side_width = parseInt($("#left-column").css("width"));
		case_width = parseInt($("#case").css("width"));
		if (isNaN(case_width)){
			case_width = 1000;
		}
		$("#content").css({"width": (case_width - side_width - 60) });
		$("#weather_frame").css({"width": (case_width - side_width - 100), "height": (screen.height - 40)});
	});
	
	///////////////////////////////////////////////////////////////////
});